#include <iostream>
#include <cstring>
#include <string>

using namespace std;

const int size = 6;
int graph[size][size];
int maxedge, nondiredge = 2;

void generate_graph() {
  memset(graph, 0, size);
  for (int i = 1; i < size; i++) {
    for (int j = 1; j < size; j++) {
      if (i != j) {
        graph[i][j] = 1;
      }
    }
  }
  graph[1][4] = 0;
  graph[4][1] = 0;
  graph[2][4] = 0;
  graph[4][2] = 0;
  
  maxedge = (size - 1) * 2 - nondiredge;
}

void dfs(int s, int l, string p) {
  p += char(s + '0');
  
  if (l == maxedge) {
    cout << p << endl;
    return;
  }
  
  for (int i = 1; i < size; i++) {
    if (graph[s][i]) {
      graph[s][i] = 0;
      graph[i][s] = 0;
      dfs(i, l + 1, p);
      graph[s][i] = 1;
      graph[i][s] = 1;
    }
  }
}

int main() {
  generate_graph();
  dfs(1, 0, "");
  
  return 0;
}
